package com.xinfu.newproject.presenter;

import com.xinfu.newproject.bean.community.InsertCommunityBean;
import com.xinfu.newproject.bean.community.InsertCommunityBody;
import com.xinfu.newproject.callback.MyCallBack;
import com.xinfu.newproject.model.community.InsertCommunityModel;
import com.xinfu.newproject.view.IView;

import io.reactivex.disposables.Disposable;

public class InsertCommunityPresenter {
    private IView.IInsertCommunityView mIInsertCommunityView;

    private InsertCommunityModel mGetCommunityModel;

    public InsertCommunityPresenter(IView.IInsertCommunityView iInsertCommunityView) {
        this.mIInsertCommunityView = iInsertCommunityView;
        mGetCommunityModel = new InsertCommunityModel();
    }

    /**
     * 新增小区
     */
    public void getCommunity() {

//        mIInsertCommunityView.showProgress();

        InsertCommunityBody insertCommunityBody = new InsertCommunityBody(mIInsertCommunityView.header(), mIInsertCommunityView.userId(), mIInsertCommunityView.projectId(), mIInsertCommunityView.tenantId());

        mGetCommunityModel.insertCommunity(insertCommunityBody, new MyCallBack<InsertCommunityBean>() {
            @Override
            public void onSuccess(InsertCommunityBean insertCommunityBean) {
//                mIInsertCommunityView.hideProgress();

                if (insertCommunityBean.isSuccess()) {
                    mIInsertCommunityView.insertCommunity(insertCommunityBean);
                } else {
                    mIInsertCommunityView.showToast(insertCommunityBean.getMessage());
                }
//                mIInsertCommunityView.showToast(insertCommunityBean.getMessage());
            }

            @Override
            public void onError(String header, String message) {
//                mIInsertCommunityView.hideProgress();
                mIInsertCommunityView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIInsertCommunityView.closeDispose(disposable);
            }
        });


    }


//    private Map<String, String> createParaMap() {
//        Map<String, String> paraMap = new HashMap<>();
//        paraMap.put("userName", mIRegisterView.getUserName());
//        return paraMap;
//    }

}
